/*
 * Copyright 2022-2029 heshuixing(https://gitee.com/heshuixing)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mercury.ec.framework.air.core.client.impl.skyecho.util;

import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

/**
 * 小太阳接口工具类
 *
 * @author hesx
 */
@Slf4j
public class SkyechoUtils {

    /**
     * 转换标准餐食类型
     * B.早餐、C.快餐、D.晚餐、H.热快餐、L.午餐、M.中餐
     *
     * @param food
     * @return
     */
    public static String getFoodType(String food) {
        switch (food) {
            case "B":
                return "早餐";
            case "C":
                return "快餐";
            case "D":
                return "晚餐";
            case "H":
                return "热快餐";
            case "L":
                return "午餐";
            case "M":
                return "中餐";
            default:
                return null;
        }
    }

    /**
     * 转换标准航班时间
     *
     * @param time
     * @return
     */
    public static String getFlightTime(String time) {
        if (StrUtil.isNotBlank(time) && time.length() == 4) {
            return time.substring(0, 2) + ":" + time.substring(2);
        }
        return null;
    }

    /**
     * 获取航班天数
     *
     * @param departTime
     * @param arriveTime
     * @return
     */
    public static int getFlightDays(String departTime, String arriveTime) {
        int days = 0;
        if (StrUtil.isNotBlank(departTime) && StrUtil.isNotBlank(arriveTime)) {
            try {
                LocalTime departLocalTime = LocalTime.parse(departTime, DateTimeFormatter.ofPattern("HH:mm"));
                LocalTime arriveLocalTime = LocalTime.parse(arriveTime, DateTimeFormatter.ofPattern("HH:mm"));
                if (arriveLocalTime.isBefore(departLocalTime)) {
                    days = 1;
                }
            } catch (Exception e) {
                log.error("获取航班天数异常", e);
            }
        }
        return days;
    }
}
